<template>
<div class="layerRtb layerRtb-threecolumn layerRtb-right">
    <three-title :title="{name:'整改'}" :close="false">
        <span tag="i" class="rig_close fr" @click="$parent.$parent.clickFourShow()"></span>
    </three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem">
            <p class="analyItemTit tx-center">整改内容</p>
            <div class="analyItemCon">
                <p class="col-md-4">
                    <span class="cLightGray pr8 fl">罚款金额</span>
                    <span>{{changeContent !== null ? changeContent.money : ''}}</span>
                </p>
                <p class="col-md-4">
                    <span class="cLightGray pr8 fl">结束时间</span>
                    <span>{{changeContent !== null ?  $utils.format('yyyy-MM-dd', changeContent.endTime) : ''}}</span>
                </p>
                <!-- <p class="col-md-4">
                    <span class="cLightGray pr8 fl">积分</span>
                    <span>{{changeContent !== null ?  changeContent.integral : ''}}</span>
                </p> -->
                 <p class="col-md-12">
                    <span class="cLightGray pr8 fl">整改描述</span>
                    <span>{{changeContent !== null ? changeContent.content : ''}}</span>
                </p>
                <p class="col-md-12" v-if='changeContent !== null' >
                    <span class="cLightGray pr8 fl">整改图片</span>
                    <rx-viewer :images="changeContent.rectifyOrderPhotoList" class="fl">
                        <div class="clearfix">
                            <div v-for="(itemImg, index) of changeContent.rectifyOrderPhotoList" :key="index" class="fl mr10">
                                <img :src="itemImg | smallImg(78, 78)" :alt="index">
                            </div>
                        </div>
                    </rx-viewer>
                </p>
            </div>
        </div>
        <div class="analyItem">
            <p class="analyItemTit tx-center">整改</p>
            <div class="analyItemCon">
                <p class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">整改描述</span>
                    <span>{{changeTextDec}}</span>
                </p>
                <p class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">图片上传</span>
                    <rx-viewer :images="changeList" class="fl">
                        <div class="clearfix">
                            <div v-for="(item, index) of changeList" :key="index" class="fl mr10">
                                <img :src="item | smallImg(78, 78)" :alt="index">
                            </div>
                        </div>
                    </rx-viewer>
                </p>
            </div>
        </div>
        <div class="analyItem" v-if="refuseBox">
            <p class="analyItemTit tx-center">打回理由</p>
            <div class="analyItemCon">
                <p class="col-md-6">
                    <span class="cLightGray pr8 fl">结束时间</span>
                    <el-date-picker
                        :picker-options="pickerBeginDateBefore"
                        v-model="endtime"
                        type="date"
                        placeholder="选择结束日期">
                    </el-date-picker>
                </p>
                <p class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">问题描述</span>
                    <textarea v-model="refustTextDec" placeholder="请输入理由" class="col-md-10"></textarea>
                </p>
                <div class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">图片上传</span>
                    <rx-upload
                        class="fl"
                        :data="{id: 11}" :init="{class: 7, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="successUpload">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                     <rx-viewer v-for="(item, index) of refustList" :key="index" class="mr10 fl" >
                        <div class="look_imgHover fl relative" style="width:78px;height:78px;" >
                            <img :src="item">
                            <div class="upload_finish_div">
                                <div class="upload_finish_bg"></div>
                                <div class="upload_finish_linksm">
                                    <div class="dis-il-block">
                                        <a href="javascript:" class="ImgBtn enlarge_viewer enlarge_link" :data-src="item"></a>
                                        <a href="javascript:" class="ImgBtn delect_link" @click="delectImg(index)"></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </rx-viewer>
                </div>
                <!-- <span class="roleFixed" @click="this.fourIndex = 0">打回历史</span> -->
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <div class="tx-center" v-if="buttonIsShow">
                    <el-radio v-model="radioValue" label="1" @change="changeRadio()">合格</el-radio>
                    <el-radio v-model="radioValue" label="2" @change="changeRadio()">不合格</el-radio>
                    <input type="button" class="uiBtn-normal uiBtn-blue" value="确定" @click="savereWork()" v-if="refuseBox">
                </div>
            </div>
        </div>
    </div>
     <!-- 五段渲染容器 -->
    <!-- <transition-group class="animated faster" enter-active-class="animated faster slideInRight" leave-active-class="animated faster slideOutRight"> -->
        <!-- 物业办理 -->
        <!-- <rx-orderHistory v-if="fourIndex === 0" :key="0"></rx-orderHistory>
    </transition-group> -->
</div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
import { getRectifyOrder, savereWork, PostJump } from '../../../Resources/Api/scene'
import rxOrderHistory from '../five/orderHistory.vue'
export default {
    props: ['type', 'role'],
    components: {
        rxOrderHistory
    },
    data () {
        return {
            pickerBeginDateBefore: {
                disabledDate: (time) => {
                    return time.getTime() < Date.now() - 8.64e7// 如果没有后面的-8.64e7就是不可以选择今天的
                }
            },
            fourIndex: 0, // 当前Index
            changeContent: null, // 整改内容
            changeList: [], // 整改图片
            changeTextDec: '', // 整改描述
            projectChangeList: [], // 项目经理整改回显
            radioValue: 0, // 合格不合格
            refuseBox: false, // 不合格按钮
            refustList: [], // 整改图片
            moneyInput: '', // 整改金额
            refustTextDec: '', // 整改描述
            endtime: '', // 结束时间
            currentId: '', // 当前的Id
            buttonIsShow: false // 按钮显示与隐藏
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo', 'twoToThreeInfo'])
    },
    created () {
        this.getRectifyOrder()
        this.buttonType()
    },
    methods: {
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 路由跳转路径拼接
        routerPath (path) {
            return this.$route.matched[1].path + '/' + path
        },
        // 按钮显示与隐藏
        buttonType () {
            if (this.userInfo.as_diquId === 39) {
                if (this.twoToThreeInfo.status === this.type) {
                    this.buttonIsShow = true
                } else {
                    this.buttonIsShow = false
                }
            } else {
                const userLevel = this.userInfo.as_level
                if (userLevel.length > 0) {
                    userLevel.forEach(ele => {
                        if (Number(ele) === 82 || Number(ele) === 83) {
                            if (this.twoToThreeInfo.status === this.type) {
                                this.buttonIsShow = true
                            } else {
                                this.buttonIsShow = false
                            }
                        } else if (Number(ele) === 47) {
                            if (Number(this.userInfo.as_cardNo) === Number(this.leftInfo.supervisor_userno)) {
                                if (this.twoToThreeInfo.status === this.type) {
                                    this.buttonIsShow = true
                                } else {
                                    this.buttonIsShow = false
                                }
                            } else {
                                this.buttonIsShow = false
                            }
                        } else {
                            this.buttonIsShow = false
                        }
                    })
                } else {
                    this.buttonIsShow = false
                }
            }
        },
        // 不合格 合格
        changeRadio () {
            if (Number(this.radioValue) === 1) {
                this.$alert('确认合格吗？', '合格提示', {
                    confirmButtonText: '确定',
                    callback: action => {
                        if (action === 'confirm') {
                            this.submitButton()
                        }
                    }
                })
                this.refuseBox = false
            } else if (Number(this.radioValue) === 2) {
                this.refuseBox = true
            }
        },
        getRectifyOrder () {
            let parm = {
                orderCode: this.$route.query.code
            }
            // 接口获取数据
            getRectifyOrder(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.changeContent = results.data.Body.rectifyOrder
                    this.projectChangeList = results.data.Body.rectifyOrderRecordList
                    if (this.projectChangeList.length > 0) {
                        // 获取项目经理最近的整改内容
                        const currentContent = this.projectChangeList.filter((item) => { return item.delFlag === 0 })
                        this.changeList = currentContent[0].recordPhotoList
                        this.changeTextDec = currentContent[0].content
                        this.currentId = currentContent[0].id
                    }
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 直接进行路由跳转路径
        routerPush (path) {
            this.$router.push(this.$route.matched[1].path + '/' + path)
        },
        // 图片上传
        successUpload (value) {
            this.refustList.push(value.src)
        },
        // 删除图片
        delectImg (index) {
            this.refustList.splice(index, 1)
        },
        // 提交打回
        savereWork () {
            if (this.twoToThreeInfo.timeoutFlag) {
                this.$message({
                    type: 'info',
                    message: '抱歉,订单超时,未提交成功'
                })
                return false
            }
            if (this.refustTextDec === '') {
                this.$message('输入打回理由')
                return false
            }
            if (this.endtime === '') {
                this.$message('必须选择结束时间')
                return false
            }
            let parm = {
                id: this.currentId,
                userName: this.userInfo.as_fullName,
                userNo: this.userInfo.as_cardNo,
                reworkEndTime: this.endtime,
                reworkReason: this.refustTextDec,
                reWorkPhoto: this.refustList
            }
            savereWork(parm).then((result) => {
                if (result.data.StatusCode === 1) {
                    this.$message('提交成功')
                    this.buttonIsShow = false
                    this.$parent.$parent.clickFourShow()
                    this.setUpDatePlate()
                } else {
                    this.$message(result.data.statusMsg)
                }
            }).catch((error) => {
                console.log(error)
            })
        },
        // 跳转阶段
        submitButton () {
            if (this.twoToThreeInfo.timeoutFlag) {
                this.$message({
                    type: 'info',
                    message: '抱歉,订单超时,未提交成功'
                })
                return false
            }
            let parm = {
                orderCode: this.$route.query.code,
                createUserNo: this.userInfo.as_cardNo,
                createUserName: this.userInfo.as_fullName
            }
            // 阶段接口
            PostJump(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.setUpDatePlate()
                    this.$parent.$parent.clickFourShow()
                }
            }).catch(error => {
                console.log(error)
            })
        }
    }
}
</script>
<style lang="scss" scoped>
    .roleFixed {
        position: absolute;
        right: 30px;
        top: 5px;
        font-family: Tahoma,Helvetica,Arial;
        font-size: 12px;
        color: #09f;
        letter-spacing: 2px;
        cursor: pointer;
    }
</style>
